<?php
    class product_edit_controller extends controllerBase
    {
        public function process()
        {
            $oProduct = $this->database->getObject('SELECT * FROM product where product_id = '.$this->iId);
            if(!$oProduct)
            {
                return $this->url->getLink('product', true, 'Product not found.');
            }
            $this->set(array('oProduct' => $oProduct));
            
            if(isset($_POST['val']))
            {
                $bResult = $this->database->update('product',$_POST['val'],'product_id = '.(int)$this->iId);
                if($bResult)
                {
                    return $this->url->getLink('product/view/'.$this->iId, true, 'Update product successful.');
                }
                else
                {
                    return $this->url->getLink('product/view/'.$this->iId, true, 'Update product fail.');
                }
            }
            $aCateories = $this->database->getListObject('SELECT * FROM category');
            $this->set(array('aCategories' => $aCateories));
        }
    }
?>
